﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessLibary;
using System.Collections;


namespace Medicare
{
    public partial class FrmMedicareCheckItem : Form
    {
        private IMedicare.IMedicare medicare;
        private DataSet queryDs = new DataSet();
        private MIItemRelationZLFacade zl;
        private MIItemRelationYPFacade yp;
        private DateTime dt;
        private int retint = 0;
        private DataSet ds=new DataSet();
        public DateTime Dt
        {
            get { return dateTimePicker1.Value; }
            set { dt = value; }
        }

        public FrmMedicareCheckItem()
        {
            InitializeComponent();
            zl = new MIItemRelationZLFacade();
            yp = new MIItemRelationYPFacade();
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            ArrayList list=new ArrayList();
            medicare = IMedicare.IMedicareFactory.Instance.CreateIMedicare();
            retint =medicare.InitHisDLL(list);
            if (retint!=0)
            {
                MessageBox.Show("医保接口初始化失败!请检查网络！");
                return;
            }


            if (ds.Tables.Count <= 0)
            {
                MessageBox.Show("没有需要上传的数据");
                return;
            }
            else 
            {
                if (ds.Tables[0].Rows.Count<=0)
                {
                    MessageBox.Show("没有需要上传的数据");
                    return;
                }
            }
            retint=medicare.UploadCorrectData(ds,0);
            if (retint!=0)
            {
                return;
            }
            MessageBox.Show("上传对照信息成功！");
        }


        private void FrmMedicareCheckItem_Load(object sender, EventArgs e)
        {

        }

        private void cboSelectType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboSelectType.SelectedIndex == 0)
            {

                InitData(0);
            }
            else if (cboSelectType.SelectedIndex==1)
            {
                InitData(1);  
            }
            
        }

        
        private void InitData(int type)
        {
           
            gridControl1.DataSource = null;
            gridView1.Columns.Clear();
            switch (type)
            {
                case 0:
                    ds = new DataSet();
                    ds=zl.DisplayCorrectInfo(Dt);
                    gridControl1.DataSource = ds.Tables[0].DefaultView;
                    break;
                case 1:
                    ds = new DataSet();
                    ds=yp.DisplayCorrectInfo(Dt);
                    gridControl1.DataSource = ds.Tables[0].DefaultView;
                    break;
                default:

                    break;
            }
 

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (ds.Tables.Count <= 0)
            {
                MessageBox.Show("没有需要上传的数据");
                return;
            }
            else
            {
                if (ds.Tables[0].Rows.Count <= 0)
                {
                    MessageBox.Show("没有需要上传的数据");
                    return;
                }
            }
            retint = medicare.UploadCorrectData(ds,1);
            if (retint != 0)
            {
                return;
            }
            MessageBox.Show("上传对照信息成功！");
        }

        
        
    }
}
